﻿@model SmallJob.Model.Banner
@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var isadd = Convert.ToBoolean(ViewData["isadd"]);
}


<link href="@Url.Content("~/Content/css/bootstrap-fileupload.min.css")" rel="stylesheet" media="screen">
@using (Html.BeginForm("Save", "Banner", FormMethod.Post, new { id = "form-banner", enctype = "multipart/form-data" }))
{
    
    <input type="hidden" name="id" value="@(isadd ? 0 : Model.ID)" />
    @Html.ValidationSummary();
    <fieldset>
        <legend>Banner</legend>
        @if (Convert.ToBoolean(ViewData["isok"]))
        {
            <div class="alert alert-success">
                <button type="button" class="close" data-dismiss="alert">&times;</button>
                Commit Success
            </div>
        }
        @Html.ValidationMessage("imageerror")
        <div id="display-image" style="position: absolute; z-index: 1;">
            @if (isadd || string.IsNullOrEmpty(Model.Url))
            {
                <div class="fileupload fileupload-new" data-provides="fileupload">
                    <div class="fileupload-preview thumbnail" style="width: 1350px; height: 430px;"></div>
                    <div>
                        <span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" name="img" /></span>
                        <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
                    </div>
                </div>
            }
            else
            {
                <div class="fileupload fileupload-exists" data-provides="fileupload">
                    <div class="fileupload-preview thumbnail" style="width: 1350px; height: 430px; line-height: 150px;">
                        @* <img src="@((Model.Url).Replace(SmallJob.Services.Code.UserUtility.GetImageBannerUpload(), "/Upload/Banner/"))" />*@
                        <img src="@Model.Url" />
                    </div>
                    <div>
                        <span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" name="img"></span>
                        <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
                    </div>
                </div>
            }
        </div>

        <div id="input-area" style="position: absolute; padding-left: 5px; padding-top: 5px; color: red; width: 1350px; height: 430px; z-index: 2;">
            <label>Title*</label>
            <input type="text" name="title" value="@(isadd ? "" : Model.Title)"/>
            @Html.ValidationMessage("titleerror")
            <label>Link</label>
            <input type="text" name="link" value="@(isadd ? "" : Model.Link)"/>
            @*<label>Is Use</label>
            <input type="checkbox" name="isuse" value="@(isadd ? false : Model.IsUse)"/>*@
            <label>Description</label>
            <textarea name="descrip" value="@(isadd ? "" : Model.Description)" rows="5"></textarea>
            <p>
                <input type="submit" value="@(isadd ? "Create" : "Edit")" />
            </p>
            <div>
                @Html.ActionLink("Back to List", "Index")
            </div>
        </div>

    </fieldset>
}



<script src="@Url.Content("~/Content/js/bootstrap-fileupload.min.js")"></script>
@if (isadd || string.IsNullOrEmpty(Model.Url))
{

}
else
{
    <script>
        $('#form-banner').submit(function (e) {
            if ($('.fileupload').find('img').attr('src') == '@(Model.Url)') {
                $('.fileupload').fileupload('clear');
            }
        });
    </script>
}

